import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 维修任务信息 */
export interface RepairTask {
  id: number // id
  repairId?: number // 维修申请单id
  maintenanceId?: number // 维修分类id
  equipmentId?: number // 设备id
  startTime?: string | Dayjs // 开始时间
  endTime?: string | Dayjs // 结束时间
  repairDuration: number // 维修时长(分钟)
  repairCost: number // 维修成本(元)
  resolved: number // 是否解决
  faultAnalysis?: string // 故障分析
  repairItem?: string // 维修事项
}

// 维修任务 API
export const RepairTaskApi = {
  // 查询维修任务分页
  getRepairTaskPage: async (params: any) => {
    return await request.get({ url: `/business/repair-task/page`, params })
  },

  // 查询维修任务统计
  getRepairRequestTaskStatistics: async (params: any) => {
    return await request.get({ url: `/business/repair-task/statistics`, params })
  },

  // 查询维修任务详情
  getRepairTask: async (id: number) => {
    return await request.get({ url: `/business/repair-task/get?id=` + id })
  },

  // 根据申请单查询维修任务详情
  getRepairTask: async (id: number) => {
    return await request.get({ url: `/business/repair-task/getByRepairId?repairId=` + id })
  },

  // 新增维修任务
  createRepairTask: async (data: RepairTask) => {
    return await request.post({ url: `/business/repair-task/create`, data })
  },

  // 修改维修任务
  updateRepairTask: async (data: RepairTask) => {
    return await request.put({ url: `/business/repair-task/update`, data })
  },

  // 删除维修任务
  deleteRepairTask: async (id: number) => {
    return await request.delete({ url: `/business/repair-task/delete?id=` + id })
  },

  /** 批量删除维修任务 */
  deleteRepairTaskList: async (ids: number[]) => {
    return await request.delete({ url: `/business/repair-task/delete-list?ids=${ids.join(',')}` })
  },

  // 导出维修任务 Excel
  exportRepairTask: async (params) => {
    return await request.download({ url: `/business/repair-task/export-excel`, params })
  },

  // 修改维修申请状态
  updateRepairRequest: async (data: RepairRequest) => {
    return await request.put({ url: `/business/repair-task/updateStatus`, data })
  }
}
